function logout() {
    $.get("/api/logout", function(data){
        if (0 == data.errno) {
            location.href = "/";
        }
    })
}

$(document).ready(function(){
    //获取用户信息
    $.get('/api/user',{},function (xhr) {
        //用户未登录
        if(xhr.errno == 4101){
            location.href = '/login.html';
        }else if(xhr.errno == 0){
            $("#user-name").html(xhr.data.username);
            $("#user-mobile").html(xhr.data.mobile);
            if (xhr.data.avatar) {
                $("#user-avatar").attr("src", xhr.data.avatar);
            }
        }

    });
})